/**
 * 使用  reduxjs/toolkit 创建reducer
 */

import {createSlice} from '@reduxjs/toolkit'

const counterStore = createSlice({
    name:"count",
    //初始化state
    initialState:{
        count:0
    },
    //修改数据的方法,同步方法
    reducers:{
        inscrement(state){
            state.count++
        },
        descrement(state){
            state.count--
        }, /** 传参 */
        addToNumber(state,action){
            state.count = action.payload + 1
        }
    }
})

//解构出来actionCreater函数,使用数组进行接收
const {inscrement,descrement,addToNumber} = counterStore.actions
//获取reducer
const reducer = counterStore.reducer

//以按需导出的方式导出actionCreacter
export {inscrement,descrement,addToNumber}
//以默认导出的方式导出reducer
export default reducer


